package com.ruoyi.bantong.controller;

import com.ruoyi.bantong.domain.BtOrganizationLevel;
import com.ruoyi.bantong.service.IBtOrganizationLevelService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 机构等级Controller
 * 
 * @author laohei
 * @date 2021-01-24
 */
@RestController
@RequestMapping("/bantong/orglevel")
public class BtOrganizationLevelController extends BaseController
{
    @Autowired
    private IBtOrganizationLevelService btOrganizationLevelService;

    /**
     * 查询机构等级列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:level:list')")
    @GetMapping("/list")
    public TableDataInfo list(BtOrganizationLevel btOrganizationLevel)
    {
        startPage();
        List<BtOrganizationLevel> list = btOrganizationLevelService.selectBtOrganizationLevelList(btOrganizationLevel);
        return getDataTable(list);
    }

    /**
     * 导出机构等级列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:level:export')")
    @Log(title = "机构等级", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BtOrganizationLevel btOrganizationLevel)
    {
        List<BtOrganizationLevel> list = btOrganizationLevelService.selectBtOrganizationLevelList(btOrganizationLevel);
        ExcelUtil<BtOrganizationLevel> util = new ExcelUtil<BtOrganizationLevel>(BtOrganizationLevel.class);
        return util.exportExcel(list, "level");
    }

    /**
     * 获取机构等级详细信息
     */
    //@PreAuthorize("@ss.hasPermi('bantong:level:query')")
    @GetMapping(value = "/{levelId}")
    public AjaxResult getInfo(@PathVariable("levelId") Integer levelId)
    {
        return AjaxResult.success(btOrganizationLevelService.selectBtOrganizationLevelById(levelId));
    }

    /**
     * 新增机构等级
     */
    //@PreAuthorize("@ss.hasPermi('bantong:level:add')")
    @Log(title = "机构等级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BtOrganizationLevel btOrganizationLevel)
    {
        btOrganizationLevel.setCreateBy(SecurityUtils.getUsername());
        return toAjax(btOrganizationLevelService.insertBtOrganizationLevel(btOrganizationLevel));
    }

    /**
     * 修改机构等级
     */
    //@PreAuthorize("@ss.hasPermi('bantong:level:edit')")
    @Log(title = "机构等级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BtOrganizationLevel btOrganizationLevel)
    {
        btOrganizationLevel.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(btOrganizationLevelService.updateBtOrganizationLevel(btOrganizationLevel));
    }

    /**
     * 删除机构等级
     */
    //@PreAuthorize("@ss.hasPermi('bantong:level:remove')")
    @Log(title = "机构等级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{levelIds}")
    public AjaxResult remove(@PathVariable Integer[] levelIds)
    {
        return toAjax(btOrganizationLevelService.deleteBtOrganizationLevelByIds(levelIds));
    }
}
